package com.example.whereismystuff.views;

import java.util.ArrayList;
import java.util.List;


import com.example.whereismystuff.classes.UserDataManager;
import com.example.whereismystuff.classes.User;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

/**
 * This method opens the layout userview and instantiates the list of users on the screen 
 * @author NullPointers
 *
 */
public class AdminUserView extends ListActivity {
	private String[] users;
	/**
	 * Method used to Instantiate Object and set the Layout for the Activity
	 * @param Bundle
	 */
	protected void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		List<User> userList = new ArrayList<User>();
		users = new String[userList.size()];
		for(int i = 0; i < users.length; i++){
			users[i] = userList.get(i).getUserName();
		}
	}
	
	/**
	 * This method redirects the admin to the view UserEdit when a username is clicked on
	 * the screen
	 */
	protected void onListItemClick(ListView list, View view, int position, long id)
	{
		super.onListItemClick(list, view, position, id);
		try
		{
			Class c = Class.forName("com.example.whereismystuff.views.UserEdit");
			Intent intent = new Intent(this, c);
			Bundle extras = new Bundle();
			extras.putString(Login.USERNAME_TAG, users[position]);
			intent.putExtras(extras);
			startActivity(intent);
		}
		catch(ClassNotFoundException e)
		{
			e.printStackTrace();
		}
	}
}
